import java.util.*;


public class Solution1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型
     */
    int count = 0;
    public int InversePairs (int[] nums) {
        // write code here
        int[] tmp = new int[nums.length];
        merge(nums,0,nums.length-1,tmp);
        return count;
    }
    private void merge(int[] data,int left ,int right ,int[] tmp) {
        if(left >= right) {
            return;
        }
        int mid = (left + right) / 2;
        merge(data,left,mid,tmp);
        merge(data,mid + 1,right,tmp);
        count %= 1000000007;
        int i = left;
        int j = mid+1;
        for(int k = left; k <= right; k++)
            tmp[k] = data[k];
        for(int k = left; k <= right; k++){
            if(i == mid + 1)
                data[k] = tmp[j++];
            else if(j == right + 1 || tmp[i] <= tmp[j])
                data[k] = tmp[i++];
            //左边比右边大，答案增加
            else{
                data[k] = tmp[j++];
                // 统计逆序对
                count += mid - i + 1;
            }
        }
        count %= 1000000007;
    }
}